package com.inspur.edp.common.expr.expresses.constant;


import com.inspur.edp.common.expr.Express;
import com.inspur.edp.common.expr.ExpressDSLGenerator;
import com.inspur.edp.common.expr.ast.ASTContext;
import com.inspur.edp.common.expr.util.DSLStringUtils;

import java.util.List;

public class StringsConstDSL implements ExpressDSLGenerator {

    @Override
    public String getKind() {
        return StringsConstExpr.KIND;
    }

    @Override
    public String generate(ASTContext context, Express express) {
        StringsConstExpr stringsConstExpr = (StringsConstExpr) express;
        List<String> stringList = stringsConstExpr.getValue();
        String listUtilsUrl = "com.inspur.edp.rule.dsl.core.function.list.ListUtils";
        context.addImport(listUtilsUrl);
        StringBuilder sb = new StringBuilder();
        sb.append("ListUtils.createStringCollection(");
        if (stringList != null && stringList.size() > 0) {
            int index = 0;
            for (String str : stringList) {
                if (index > 0) {
                    sb.append("," + "\"" + DSLStringUtils.handle(str) + "\"");
                } else {
                    sb.append("\"" + DSLStringUtils.handle(str) + "\"");
                }
                index++;
            }
        } else {
            sb.append("null");
        }
        sb.append(")");
        return sb.toString();
    }

}
